package com.ygqh.baby.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

@Component
public class ThreadPool {
	protected final Logger logger = Logger.getLogger(this.getClass());
	private final int nThreads = 5;
	private final ExecutorService executorService;

	public ThreadPool() {
		super();
		this.executorService = Executors.newFixedThreadPool(nThreads);
	}

	synchronized public ExecutorService getExecutorService() {
		boolean shutdown = executorService.isShutdown();
		if (shutdown) {
			logger.error("有接口调用了 executorService.shutdown() ");
			return Executors.newFixedThreadPool(nThreads);
		}
		return executorService;
	}

	/**
	 * 调用后将不再获取新任务
	 * 
	 * @Title: shutdown
	 * @param 入参
	 * @return void 返回类型
	 * @author （guohao）
	 * @throws
	 * @date 2017年7月7日 上午10:22:30
	 * @version V1.0
	 */
	public void shutdown() {
		executorService.shutdown();
	}

}
